<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    div{
        border:2px solid palevioletred;
        width: 100px;
        height: 100px;
    }
   
    </style>
</head>
<body>
    <div>
        <button>111</button>
    </div>
    
    <script>
        //兼容性函数
        var divEle=document.querySelector("div")
function getStyle(ele,styleName){
    if(window.getComputedStyle)
    {
        return getComputedStyle(ele,null)[styleName]
    }
    else{
        return ele.currentStyle[styleName];
    }
}
console.log(getStyle(divEle,"width"))
    </script>
</body>
</html>